package zozopo.attendance;

import java.util.Map;

import org.apache.struts2.interceptor.SessionAware;

import zozopo.attendance.operations.OperatorAttendanceOS;
import zozopo.attendance.operations.OperatorAttendanceTB;
import zozopo.background.operator.operations.OperatorOS;
import zozopo.background.operator.operations.OperatorTB;
import zozopo.background.operator.operations.OperatorlimitedTB;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionSupport;

public class ModifyOperatorAction extends ActionSupport implements Action,SessionAware{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private static final String limitedCode ="ATTENDANCE.OPERATOR";
	
	//传入参数
	private int operatorid;
	
	
	private boolean monday_operator;
	private boolean tuesday_operator;
	private boolean wednesday_operator;
	private boolean thursday_operator;
	private boolean friday_operator;
	private boolean saturday_operator;
	private boolean sunday_operator;
	
	private String workhours_operator;
	private String offhours_operator;
	
	
	private double basicpay_operator;
	private double jobpay_operator;
	private double markpay_operator;
	
 
	//传出参数
	OperatorAttendanceTB operatorofattendance;
	
	OperatorTB operator;
	
	private Map<Object, Object> session;
	public void setSession(Map arg0) {
		// TODO Auto-generated method stub
		session = arg0;
	}
	public String execute(){
		
		OperatorAttendanceOS operatorOfAttendanceOS = new OperatorAttendanceOS();
		OperatorOS operatorOS = new OperatorOS(operatorOfAttendanceOS.getConn());
		
		
		
		
		operator = operatorOS.getInfo(operatorid);
			
		operatorofattendance = new OperatorAttendanceTB();
		operatorofattendance.setOperatorid_operator(operatorid);
			
		operatorofattendance.setWorkhours_operator(workhours_operator);
		operatorofattendance.setOffhours_operator(offhours_operator);
			
		operatorofattendance.setBasicpay_operator(basicpay_operator);
		operatorofattendance.setJobpay_operator(jobpay_operator);
		operatorofattendance.setMarkpay_operator(markpay_operator);
			
		operatorofattendance.setName_operator(operator.getName_operator());
		operatorofattendance.setFirstname_operator(operator.getFirstname_operator());
		operatorofattendance.setLastname_operator(operator.getLastname_operator());
			
		operatorofattendance.setMonday_operator(monday_operator);
		operatorofattendance.setTuesday_operator(tuesday_operator);
		operatorofattendance.setWednesday_operator(wednesday_operator);
		operatorofattendance.setThursday_operator(thursday_operator);
		operatorofattendance.setFriday_operator(friday_operator);
		operatorofattendance.setSaturday_operator(saturday_operator);
		operatorofattendance.setSunday_operator(sunday_operator);
			
		if(!operatorOfAttendanceOS.updateByOperatorId(operatorofattendance)){ //如果插入失败
			operatorOfAttendanceOS.releaseConnection();
			return ERROR;
		}
		
		operatorofattendance = operatorOfAttendanceOS.getInfoByOperatorid(operatorid);
			
		
		
		//*/
		operatorOfAttendanceOS.releaseConnection();
		
		return SUCCESS;
		
	}

	public void validate() {
		//权限处理
		
		OperatorTB operator = (OperatorTB)session.get("operatorInfo"); 
	
		if(operator == null){
			addFieldError("errormessage",getText("operator.timeoutornotlogin"));
			return ; 
		} 
		//用户权限
		Map<String,OperatorlimitedTB> operatorlimitedMap = (Map<String,OperatorlimitedTB>)session.get("operatorlimitedMap");
		
		if(operatorlimitedMap.get(limitedCode) == null){
			addFieldError("errormessage","用户没有添加售后信息权限.");
			return;
		}
		
		
		
	}
	
	
	
	public static String getLimitedcode() {
		return limitedCode;
	}
	public int getOperatorid() {
		return operatorid;
	}
	public void setOperatorid(int operatorid) {
		this.operatorid = operatorid;
	}
	public boolean isMonday_operator() {
		return monday_operator;
	}
	public void setMonday_operator(boolean monday_operator) {
		this.monday_operator = monday_operator;
	}
	public boolean isTuesday_operator() {
		return tuesday_operator;
	}
	public void setTuesday_operator(boolean tuesday_operator) {
		this.tuesday_operator = tuesday_operator;
	}
	public boolean isWednesday_operator() {
		return wednesday_operator;
	}
	public void setWednesday_operator(boolean wednesday_operator) {
		this.wednesday_operator = wednesday_operator;
	}
	public boolean isThursday_operator() {
		return thursday_operator;
	}
	public void setThursday_operator(boolean thursday_operator) {
		this.thursday_operator = thursday_operator;
	}
	public boolean isFriday_operator() {
		return friday_operator;
	}
	public void setFriday_operator(boolean friday_operator) {
		this.friday_operator = friday_operator;
	}
	public boolean isSaturday_operator() {
		return saturday_operator;
	}
	public void setSaturday_operator(boolean saturday_operator) {
		this.saturday_operator = saturday_operator;
	}
	public boolean isSunday_operator() {
		return sunday_operator;
	}
	public void setSunday_operator(boolean sunday_operator) {
		this.sunday_operator = sunday_operator;
	}
	public String getWorkhours_operator() {
		return workhours_operator;
	}
	public void setWorkhours_operator(String workhours_operator) {
		this.workhours_operator = workhours_operator;
	}
	public String getOffhours_operator() {
		return offhours_operator;
	}
	public void setOffhours_operator(String offhours_operator) {
		this.offhours_operator = offhours_operator;
	}
	public double getBasicpay_operator() {
		return basicpay_operator;
	}
	public void setBasicpay_operator(double basicpay_operator) {
		this.basicpay_operator = basicpay_operator;
	}
	public OperatorAttendanceTB getOperatorofattendance() {
		return operatorofattendance;
	}
	public void setOperatorofattendance(OperatorAttendanceTB operatorofattendance) {
		this.operatorofattendance = operatorofattendance;
	}
	public OperatorTB getOperator() {
		return operator;
	}
	public void setOperator(OperatorTB operator) {
		this.operator = operator;
	}
	public Map<Object, Object> getSession() {
		return session;
	}
	public double getJobpay_operator() {
		return jobpay_operator;
	}
	public void setJobpay_operator(double jobpay_operator) {
		this.jobpay_operator = jobpay_operator;
	}
	public double getMarkpay_operator() {
		return markpay_operator;
	}
	public void setMarkpay_operator(double markpay_operator) {
		this.markpay_operator = markpay_operator;
	}

}
